package com.yg.controller;


import com.yg.pojo.TOrderItem;
import com.yg.service.TOrderItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author kotori
 * @since 2022-11-18
 */
@Controller
@RequestMapping("/orderItem")
public class TOrderItemController {
    @Autowired
    private TOrderItemService orderItemService;

    @GetMapping("/info/{orderId}")
    public ModelAndView info(@PathVariable("orderId") String orderId, ModelAndView modelAndView, HttpSession session) {
        String user = (String) session.getAttribute("loginUser");
        if (user == null) {
            modelAndView.setViewName("user/login");
        } else {
            List<TOrderItem> order = orderItemService.getOrderItemsByOrderId(orderId);
            modelAndView.addObject("order", order);
            modelAndView.setViewName("/order/order_info");
        }
        return modelAndView;
    }
}

